#ifndef _FTPHANDLER_HPP
#define _FTPHANDLER_HPP

#include "ftppool.hpp"
#include <string>
#include "datacollection.hpp"
#include <sstream>
#include "ftpprofiles.hpp"
#include <exception>
#include <boost/date_time/posix_time/posix_time.hpp>

using namespace boost::posix_time;
using namespace com_oocl_monitor::domain;
using namespace com_oocl_monitor::system;
using std::stringstream;

namespace com_oocl_monitor {
	namespace service {
		class FtpService {
		public:
			explicit FtpService(FtpPool *pool);
			~FtpService();
			DataCollection* perform(const Profile profile, const ptime startTime, const ptime endTime);

		private:
			DataCollection *cacheToData(const Profile& profile, const ptime& startTime, const ptime& endTime);
			inline DataPair parseUNIXLine(const string&,stringstream &ss);
			inline DataPair parseDOSLine(const string&,stringstream &ss);
			static size_t write_fun(char * buff, size_t size, size_t nmenb, void * data);
		private:
			FtpPool *_pool;
			stringstream _cache;
		};

		class FtpException :public std::exception {
		public:
			FtpException(const string& host) :_host(host) {}
			virtual const char* what() const throw() {
				return _host.c_str();
			}
			string Host() const {
				return _host;
			}
		private:
			string _host;
		};
	}
}

#endif // _FTPHANDLER_HPP
